import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
"""
conftest.py：存放fixture夹具
conftest.py是固定的、写死的，不要改名字
"""

@pytest.fixture()
def login1():
    print("用户登录")

@pytest.fixture()
def file():
    print("打开文件")
    yield
    print("关闭文件")

@pytest.fixture(name='driver')
def open_browser():
    driver = webdriver.Chrome(service=Service('chromedriver.exe'))
    driver.get("https://www.baidu.com")
    driver.maximize_window()
    # 上面是setup
    yield driver # 返回值，yield当成return就可以了
    # 下面是teardown
    driver.quit()


@pytest.fixture(scope='class',autouse=False)
def setup_teardown():
    print("打开浏览器")
    print("浏览器最大化")
    yield
    print("浏览器退出")